package com.shop.controller;

import com.shop.bean.Product;
import com.shop.bean.User;
import com.shop.dao.CartDao;
import com.shop.service.IProductService;
import com.shop.util.Page;
import com.shop.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("shopping")
public class ShoppingPageController {

    @Autowired
    IProductService productService;


    @RequestMapping("index")
    public String index(){
        return "shopping/index.html";
    }

    @RequestMapping("login")
    public String login(){
        return "shopping/login.html";
    }

    @RequestMapping("cart")
    public String cart(){
        return "shopping/cart.html";
    }


    @RequestMapping("shop")
    public String shop(Product product, String text, Page page, Model model){
        if (page.getPage()==0){page.setPage(1);}
        if (page.getLimit()==0){page.setLimit(9);}
        model.addAttribute("product",product);
        model.addAttribute("text",text);
        model.addAttribute("page",page);

        return "shopping/shop.html";
    }

    @RequestMapping("product-single")
    public String product(Integer id, Model model){
        model.addAttribute("id",id);
        return "shopping/product-single.html";
    }


    @RequestMapping("userinfo")
    public String userinfo(HttpSession session){
        return "shopping/userinfo.html";
    }


    @RequestMapping("checkout")
    public String checkout(HttpSession session,String productids,String counts,Model model){
        model.addAttribute("productids",productids);
        model.addAttribute("counts",counts);
        return "shopping/checkout.html";
    }



    @RequestMapping("payment")
    public String payment(Integer id,Model model){
        model.addAttribute("id",id);
        return "shopping/payment.html";
    }

    @RequestMapping("about")
    public String about(Integer id,Model model){
        return "shopping/about.html";
    }

    @RequestMapping("blog")
    public String blog(Integer id,Model model){
        return "shopping/blog.html";
    }

    @RequestMapping("contact")
    public String contact(Integer id,Model model){
        return "shopping/contact.html";
    }



}
